package com.lcf.app.redis;

import com.alibaba.fastjson.JSON;
import com.lcf.app.redis.model.User;
import com.lcf.app.redis.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ChenFei
 * @date 2021/10/29
 */
@Slf4j
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("getUser")
    public User getUser() {

        log.info("------------------>@Cacheable-测试");
        User user = userService.getUser("1");
        log.info("------------------>取出:{}", JSON.toJSONString(user));

        user = userService.getUser("1");
        log.info("------------------>取出:{}", JSON.toJSONString(user));

        userService.remove("1");//删除缓存测试
        user = userService.getUser("1");
        log.info("------------------>取出:{}", JSON.toJSONString(user));

        userService.updateUser(new User().setId("1").setName("ChenFei"));//更新缓存测试
        user = userService.getUser("1");
        log.info("------------------>取出:{}", JSON.toJSONString(user));


        return user;

    }

}
